package com.ruoyi.paper.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.paper.domain.ExamStudentPaper;
import com.ruoyi.paper.service.IExamStudentPaperService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考生答卷Controller
 * 
 * @author ruoyi
 * @date 2025-04-14
 */
@Controller
@RequestMapping("/jxsx/studentPaper")
public class ExamStudentPaperController extends BaseController
{
    private String prefix = "jxsx/paper";

    @Autowired
    private IExamStudentPaperService examStudentPaperService;

    @RequiresPermissions("jxsx:paper:view")
    @GetMapping()
    public String paper()
    {
        return prefix + "/paper";
    }

    /**
     * 查询考生答卷列表
     */
    @RequiresPermissions("jxsx:paper:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamStudentPaper examStudentPaper)
    {
        startPage();
        List<ExamStudentPaper> list = examStudentPaperService.selectExamStudentPaperList(examStudentPaper);
        return getDataTable(list);
    }

    /**
     * 导出考生答卷列表
     */
    @RequiresPermissions("jxsx:paper:export")
    @Log(title = "考生答卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExamStudentPaper examStudentPaper)
    {
        List<ExamStudentPaper> list = examStudentPaperService.selectExamStudentPaperList(examStudentPaper);
        ExcelUtil<ExamStudentPaper> util = new ExcelUtil<ExamStudentPaper>(ExamStudentPaper.class);
        return util.exportExcel(list, "考生答卷数据");
    }

    /**
     * 新增考生答卷
     */
    @RequiresPermissions("jxsx:paper:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存考生答卷
     */
    @RequiresPermissions("jxsx:paper:add")
    @Log(title = "考生答卷", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExamStudentPaper examStudentPaper)
    {
        return toAjax(examStudentPaperService.insertExamStudentPaper(examStudentPaper));
    }

    /**
     * 修改考生答卷
     */
    @RequiresPermissions("jxsx:paper:edit")
    @GetMapping("/edit/{studentPaperId}")
    public String edit(@PathVariable("studentPaperId") String studentPaperId, ModelMap mmap)
    {
        ExamStudentPaper examStudentPaper = examStudentPaperService.selectExamStudentPaperByStudentPaperId(studentPaperId);
        mmap.put("examStudentPaper", examStudentPaper);
        return prefix + "/edit";
    }

    /**
     * 修改保存考生答卷
     */
    @RequiresPermissions("jxsx:paper:edit")
    @Log(title = "考生答卷", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExamStudentPaper examStudentPaper)
    {
        return toAjax(examStudentPaperService.updateExamStudentPaper(examStudentPaper));
    }

    /**
     * 删除考生答卷
     */
    @RequiresPermissions("jxsx:paper:remove")
    @Log(title = "考生答卷", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(examStudentPaperService.deleteExamStudentPaperByStudentPaperIds(ids));
    }
}
